import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useTokenStore = defineStore('tokenManager', () => {

    const token = ref<string>('');
    const bearerToken = computed(() => {
        return "Bearer " + token.value;
    })
    function updateToken() {
        token.value = "token:" + (Math.random() * 10);
    }
    function setToken(userToken: string) {
        token.value = userToken;
    }
    function getToken() {
        return token.value;
    }
    function removeToken() {
        return token.value = '';
    }

    return { token, bearerToken, getToken, updateToken, setToken, removeToken }

}, {
    persist: true,
},)